package org.coco24.pmgame.pack

import com.badlogic.gdx.utils.Array
/**
 * Created by coco24 on 17-12-17.
 */
enum class Type
{
    //    const val NORMAL = 0
//    const val FIGHTING = 1
//    const val FLYING = 2
//    const val POISON = 3
//    const val GROUND = 4
//    const val FIGHTING = 1
//    const val FLYING = 2
//    const val POISON = 3
    NORMAL,
    FIGHTING, FLYING, POISON, GROUND, ROCK, BUG, GHOST, STEEL, FIRE, WATER, GRASS, ELECTRIC, PSYCHIC, ICE, DRAGON, DARK, FAIRY, UNKNOWN;


    companion object
    {
        @JvmStatic
        fun getName(type: Type): String
        {
            when (type)
            {
                NORMAL -> return "一般"
                FIGHTING -> return "格斗"
                FLYING -> return "飞行"
                POISON -> return "毒"
                GROUND -> return "地面"
                ROCK -> return "岩石"
                BUG -> return "虫"
                GHOST -> return "幽灵"
                STEEL -> return "钢"
                FIRE -> return "火"
                WATER -> return "水"
                GRASS -> return "草"
                ELECTRIC -> return "电"
                PSYCHIC -> return "超能"
                ICE -> return "冰"
                DRAGON -> return "龙"
                DARK -> return "恶"
                FAIRY -> return "妖精"
                else -> return "???"
            }
        }

        @JvmStatic
        fun getFromEnName(name: String): Type
        {
            when (name)
            {
                "normal" -> return NORMAL
                "fighting" -> return FIGHTING
                "flying" -> return FLYING
                "poison" -> return POISON
                "ground" -> return GROUND
                "rock" -> return ROCK
                "bug" -> return BUG
                "ghost" -> return GHOST
                "steel" -> return STEEL
                "fire" -> return FIRE
                "water" -> return WATER
                "grass" -> return GRASS
                "electric" -> return ELECTRIC
                "psychic" -> return PSYCHIC
                "ice" -> return ICE
                "dragon" -> return DRAGON
                "dark" -> return DARK
                "fairy" -> return FAIRY
                else -> return UNKNOWN
            }
        }

        fun getFromEnNameL(name: String): Type
        {
            when (name)
            {
                "NORMAL" -> return NORMAL
                "FIGHTING" -> return FIGHTING
                "FLYING" -> return FLYING
                "POISON" -> return POISON
                "GROUND" -> return GROUND
                "ROCK" -> return ROCK
                "BUG" -> return BUG
                "GHOST" -> return GHOST
                "STEEL" -> return STEEL
                "FIRE" -> return FIRE
                "WATER" -> return WATER
                "GRASS" -> return GRASS
                "ELECTRIC" -> return ELECTRIC
                "PSYCHIC" -> return PSYCHIC
                "ICE" -> return ICE
                "DRAGON" -> return DRAGON
                "DARK" -> return DARK
                "FAIRY" -> return FAIRY
                else -> return UNKNOWN
            }
        }

        @JvmStatic
        fun getChartPercent(type1: Type, type2: Type): Float
        {
            when (type1)
            {
                NORMAL -> return getDefChart(type2, Array.with(), Array.with(ROCK, STEEL), Array.with(GHOST))
                FIGHTING -> return getDefChart(type2, Array.with(NORMAL, ROCK, STEEL, ICE, DARK), Array.with(FLYING, POISON, BUG, PSYCHIC, FAIRY), Array.with(GHOST))
                FLYING -> return getDefChart(type2, Array.with(FIGHTING, BUG, GRASS), Array.with(ROCK, STEEL, ELECTRIC), Array())
                POISON -> return getDefChart(type2, Array.with(GRASS, FAIRY), Array.with(POISON, GROUND, ROCK, GHOST), Array.with(STEEL))
                GROUND -> return getDefChart(type2, Array.with(POISON, ROCK, STEEL, FIRE, ELECTRIC), Array.with(BUG, GRASS), Array.with(FLYING))
                ROCK -> return getDefChart(type2, Array.with(FLYING, BUG, FIRE, ICE), Array.with(FIGHTING, GROUND, STEEL), Array())
                BUG -> return getDefChart(type2, Array.with(GRASS, PSYCHIC, DARK), Array.with(FIGHTING, FLYING, POISON, GHOST, STEEL, FIRE, FAIRY), Array())
                GHOST -> return getDefChart(type2, Array.with(GHOST, PSYCHIC), Array.with(STEEL, DARK), Array.with(NORMAL))
                STEEL -> return getDefChart(type2, Array.with(ROCK, ICE, FAIRY), Array.with(STEEL, FIRE, WATER, ELECTRIC), Array())
                FIRE -> return getDefChart(type2, Array.with(BUG, STEEL, GRASS, ICE), Array.with(ROCK, FIRE, WATER, DRAGON), Array())
                WATER -> return getDefChart(type2, Array.with(GROUND, ROCK, FIRE), Array.with(WATER, GRASS, DRAGON), Array())
                GRASS -> return getDefChart(type2, Array.with(GROUND, ROCK, WATER), Array.with(FLYING, POISON, BUG, STEEL, FIRE, GRASS, DRAGON), Array())
                ELECTRIC -> return getDefChart(type2, Array.with(FLYING, WATER), Array.with(GRASS, ELECTRIC, DRAGON), Array.with(GROUND))
                PSYCHIC -> return getDefChart(type2, Array.with(FIGHTING, POISON), Array.with(STEEL, PSYCHIC), Array.with(DARK))
                ICE -> return getDefChart(type2, Array.with(FLYING, GROUND, GRASS, DRAGON), Array.with(STEEL, FIRE, WATER, ICE), Array())
                DRAGON -> return getDefChart(type2, Array.with(DRAGON), Array.with(STEEL), Array.with(FAIRY))
                DARK -> return getDefChart(type2, Array.with(GHOST, PSYCHIC), Array.with(FIGHTING, STEEL, DARK, FAIRY), Array())
                FAIRY -> return getDefChart(type2, Array.with(FIGHTING, DRAGON, DARK), Array.with(POISON, STEEL, FIRE), Array())
                else -> return getDefChart(type2, Array(), Array(), Array())
            }
        }

        @JvmStatic
        fun getDefChart(defType: Type, double: Array<Type>, half: Array<Type>, noeffect: Array<Type>): Float
        {
            for (type in double)
            {
                if (type == defType) return 2f
            }
            for (type in half)
            {
                if (type == defType) return 0.5f
            }
            for (type in noeffect)
            {
                if (type == defType) return 0f
            }
            return 1f
        }
    }
}